package com.group.zsxm.web.action;

import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.config.ParentPackage;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fins.gt.server.GridServerHandler;
import com.group.core.Constants;
import com.group.core.common.Message;
import com.group.core.common.Page;
import com.group.zsxm.entity.XtDict;
import com.group.zsxm.entity.Xtuser;
import com.group.zsxm.service.ExcelService;
import com.group.zsxm.service.JfhsbService;
import com.group.zsxm.service.ZsdwService;
import com.group.zsxm.web.common.BaseAction;
@ParentPackage("appDefault")
@Scope("prototype")
@Controller
@Results( { 
			@Result(name = "jfh", value = "/WEB-INF/jsp/jfhsb/jfh.jsp"),
			@Result(name = "jfhsh", value = "/WEB-INF/jsp/jfhsb/jfh_sh.jsp"),
			@Result(name = "jfhzf", value = "/WEB-INF/jsp/jfhsb/jfh_zf.jsp"),
			@Result(name = "jfhaj", value = "/WEB-INF/jsp/jfhsb/jfh_aj.jsp"),
			@Result(name = "pjfhsh", value = "/WEB-INF/jsp/jfhsb/jfh_sh_d.jsp"),
			@Result(name = "pjfhzf", value = "/WEB-INF/jsp/jfhsb/jfh_zf_d.jsp"),
			@Result(name = "pjfhaj", value = "/WEB-INF/jsp/jfhsb/jfh_aj_d.jsp"),
		})
public class JfhsbAction extends BaseAction{

	@Autowired
	@Qualifier("jfhsbService")
	private JfhsbService jfhsbService;
	
	@Autowired
	@Qualifier("excelService")
	private ExcelService excelService;
	
	@Autowired
	@Qualifier("zsdwService")
	private ZsdwService zsdwService;
	private Map<Integer, List<XtDict>> xtdlbs;
	private String ryid;
	private Map<String, String> jfh;
	private Map<String, String> jbxx;
	private List<XtDict> xtdict15; 
	private List<XtDict> xtdict25;
	private List<XtDict> xtdict16;
	private List<XtDict> xtdict26; 
	private String opttype;
	private Map<String, String> zsdw;
	private List<XtDict> xtdict14;
	private String sbids;
	private String ttype;
	private Integer shbz;
	private Integer zfbz;
	
	private List<Map<String, String>> fj3s11;
	private List<Map<String, String>> fj3s12;
	
	public List<Map<String, String>> getFj3s11() {
		return fj3s11;
	}

	public void setFj3s11(List<Map<String, String>> fj3s11) {
		this.fj3s11 = fj3s11;
	}

	public List<Map<String, String>> getFj3s12() {
		return fj3s12;
	}

	public void setFj3s12(List<Map<String, String>> fj3s12) {
		this.fj3s12 = fj3s12;
	}

	public String getTtype() {
		return ttype;
	}

	public void setTtype(String ttype) {
		this.ttype = ttype;
	}

	public String getSbids() {
		return sbids;
	}
	
	public void setSbids(String sbids) {
		this.sbids = sbids;
	}
	private Xtuser xtuser ;
	public Xtuser getXtuser() {
		return xtuser;
	}

	public void setXtuser(Xtuser xtuser) {
		this.xtuser = xtuser;
	}
	public void onPrepare() {
		xtuser = (Xtuser)getSession().getAttribute(Constants.USER_SESSION_KEY);
	}
	

	public void getShzfList() {
		GridServerHandler gridHandler = new GridServerHandler(getRequest(), getResponse());
		getLimitPage().setRowAttributes(gridHandler.getTotalRowNum(), gridHandler.getPageNum(), gridHandler.getPageSize());
		Map param = getParameterSimpleMap();
		Page page = (Page) jfhsbService.getShzfList(getLimitPage(), param, gridHandler.getSingleSortInfo(), gridHandler.getFilterInfo(),xtuser.getUserid());
		gridHandler.setTotalRowNum(page.getTotalCount());
		gridHandler.setData((List) page.getData());
		renderText(gridHandler.getLoadResponseText());
	}

	public void exportShzfList() {
		GridServerHandler gridHandler = new GridServerHandler(getRequest(), getResponse());
		Map param = gridHandler.getGridRequestParameters();
		List list = (List) jfhsbService.getShzfList(null, param, gridHandler.getSingleSortInfo(), gridHandler.getFilterInfo(),xtuser.getUserid());
		try {
			gridHandler.exportXLSfromMaps(list);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void doJfhShzfBySb(){
		Map<String, Object> mapOut = new HashMap<String, Object>();
		try{
			jfhsbService.doJfhShzfBySb(xtuser.getUserid(),ryid);
			message = new Message("1","保存成功");
		}catch(Exception e){
			message = new Message("-1",e.getMessage());
		}
		mapOut.put("message", message);
		this.renderJson(mapOut);
	}
	
	public String execute(){
		return "jfh";
	}
	
	public String getJfhsh(){
		return "jfhsh";
	}
	public String preJfhsh(){
		return "pjfhsh";
	}
	
	
	public String getJfhzf(){
		jbxx = jfhsbService.getJfhsbJbxxWithShzf(xtuser.getUserid());
		return "jfhzf";
	}
	
	public void checkSb(){
		
	}
	
	public String preJfhzf(){
		zsdw = zsdwService.preRyxxU(xtuser.getUserid(), ryid);
		xtdlbs = zsdwService.getDictListByLbid("14");
		xtdict14 = xtdlbs.get(14);
		xtdlbs = zsdwService.getDictListByLbid("15");
		xtdict15 = xtdlbs.get(15);
		xtdlbs = zsdwService.getDictListByLbid("25");
		xtdict25 = xtdlbs.get(25);
		xtdlbs = zsdwService.getDictListByLbid("26");
		xtdict26 = xtdlbs.get(26);
		
		shbz = jfhsbService.getJfhType(xtuser.getUserid(), ryid, "1");
		zfbz = jfhsbService.getJfhType(xtuser.getUserid(), ryid, "2");
		
		jfh = jfhsbService.preJfhshzf(xtuser.getUserid(), ryid);
		return "pjfhzf";
	}
	
	/***
	 * 检查人才的附件信息，判断是否上传了相关必须附件材料
	 */
	public void checkRcfjInfo(){
		Map<String, Object> mapOut = new HashMap<String, Object>();
		try{
			//jfhsbService.checkFjInfo(xtuser.getUserid(), ryid, ttype);
			message = new Message("1","检查成功");
		}catch(Exception e){
			message = new Message("-1",e.getMessage());
		}
		mapOut.put("message", message);
		this.renderJson(mapOut);
	}
	
	
	public void doSaveJfhshzf(){
		
		Map<String, Object> mapOut = new HashMap<String, Object>();
		try{
			jfhsbService.doSaveJfhshzf(xtuser.getUserid(), jfh,ryid);
			message = new Message("1","保存成功");
		}catch(Exception e){
			message = new Message("-1",e.getMessage());
		}
		mapOut.put("message", message);
		this.renderJson(mapOut);
	}
	
	public void doJfhshzfD(){
		Map<String, Object> mapOut = new HashMap<String, Object>();
		try{
			jfhsbService.doJfhshzfD(xtuser.getUserid(), ryid);
			message = new Message("1","删除成功");
		}catch(Exception e){
			message = new Message("-1",e.getMessage());
		}
		mapOut.put("message", message);
		this.renderJson(mapOut);
	}
	/**
	 * 安家
	 * @return
	 */
	public String getJfhaj(){
		jbxx = jfhsbService.getJfhsbJbxxWithShzf(xtuser.getUserid());
		return "jfhaj";
	}
	public String preJfhaj(){
		zsdw = zsdwService.preRyxxU(xtuser.getUserid(), ryid);
		xtdlbs = zsdwService.getDictListByLbid("14");
		xtdict14 = xtdlbs.get(14);
		xtdlbs = zsdwService.getDictListByLbid("15");
		xtdict15 = xtdlbs.get(15);
		xtdlbs = zsdwService.getDictListByLbid("25");
		xtdict25 = xtdlbs.get(25);
		xtdlbs = zsdwService.getDictListByLbid("26");
		xtdict26 = xtdlbs.get(26);
		jfh = jfhsbService.preJfhAjf(xtuser.getUserid(), ryid);
		return "pjfhaj";
	}


	public void getAjfList() {
		GridServerHandler gridHandler = new GridServerHandler(getRequest(), getResponse());
		getLimitPage().setRowAttributes(gridHandler.getTotalRowNum(), gridHandler.getPageNum(), gridHandler.getPageSize());
		Map param = getParameterSimpleMap();
		Page page = (Page) jfhsbService.getAjfList(getLimitPage(), param, gridHandler.getSingleSortInfo(), gridHandler.getFilterInfo(),xtuser.getUserid());
		gridHandler.setTotalRowNum(page.getTotalCount());
		gridHandler.setData((List) page.getData());
		renderText(gridHandler.getLoadResponseText());
	}

	public void exportAjfList() {
		GridServerHandler gridHandler = new GridServerHandler(getRequest(), getResponse());
		Map param = getParameterSimpleMap();
		List list = (List) jfhsbService.getAjfList(null, param, gridHandler.getSingleSortInfo(), gridHandler.getFilterInfo(),xtuser.getUserid());
		try {
			gridHandler.exportXLSfromMaps(list);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void doJfhAjfBySb(){
		Map<String, Object> mapOut = new HashMap<String, Object>();
		try{
			jfhsbService.doJfhAjfBySb(xtuser.getUserid(),ryid);
			message = new Message("1","保存成功");
		}catch(Exception e){
			message = new Message("-1",e.getMessage());
		}
		mapOut.put("message", message);
		this.renderJson(mapOut);
	}
	
	public void doSaveJfhaj(){
		
		Map<String, Object> mapOut = new HashMap<String, Object>();
		try{
			jfhsbService.doSaveJfhaj(xtuser.getUserid(), jfh,ryid);
			message = new Message("1","保存成功");
		}catch(Exception e){
			message = new Message("-1",e.getMessage());
		}
		mapOut.put("message", message);
		this.renderJson(mapOut);
	}
	
	
	public void doJfhajfD(){
		Map<String, Object> mapOut = new HashMap<String, Object>();
		try{
			jfhsbService.doJfhajfD(xtuser.getUserid(), ryid);
			message = new Message("1","删除成功");
		}catch(Exception e){
			message = new Message("-1",e.getMessage());
		}
		mapOut.put("message", message);
		this.renderJson(mapOut);
	}
	
	

	public void doExportExcel(){
		OutputStream os = null;
		try{
			String bt = "金凤凰高层次人才.xls";
			this.getResponse().reset();
			os = getResponse().getOutputStream();
			this.getResponse().setContentType("application/msexcel;charsert=GBK");
			this.getResponse().setHeader("Content-Disposition","attachment; filename="+new String (bt.getBytes(),"ISO8859-1"));
			excelService.doExportDwjfh(os, xtuser.getUserid(),xtuser.getCnname(),xtuser.getLogindate());
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(os != null){
				try{
					os.close();
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}
	}
	
	public JfhsbService getJfhsbService() {
		return jfhsbService;
	}

	public void setJfhsbService(JfhsbService jfhsbService) {
		this.jfhsbService = jfhsbService;
	}

	public Map<String, String> getJfh() {
		return jfh;
	}

	public void setJfh(Map<String, String> jfh) {
		this.jfh = jfh;
	}

	public Map<String, String> getJbxx() {
		return jbxx;
	}

	public void setJbxx(Map<String, String> jbxx) {
		this.jbxx = jbxx;
	}

	public List<XtDict> getXtdict15() {
		return xtdict15;
	}

	public void setXtdict15(List<XtDict> xtdict15) {
		this.xtdict15 = xtdict15;
	}

	public List<XtDict> getXtdict25() {
		return xtdict25;
	}

	public void setXtdict25(List<XtDict> xtdict25) {
		this.xtdict25 = xtdict25;
	}

	public List<XtDict> getXtdict16() {
		return xtdict16;
	}

	public void setXtdict16(List<XtDict> xtdict16) {
		this.xtdict16 = xtdict16;
	}

	public String getOpttype() {
		return opttype;
	}

	public void setOpttype(String opttype) {
		this.opttype = opttype;
	}

	public Map<Integer, List<XtDict>> getXtdlbs() {
		return xtdlbs;
	}

	public void setXtdlbs(Map<Integer, List<XtDict>> xtdlbs) {
		this.xtdlbs = xtdlbs;
	}

	public List<XtDict> getXtdict26() {
		return xtdict26;
	}

	public void setXtdict26(List<XtDict> xtdict26) {
		this.xtdict26 = xtdict26;
	}

	public ZsdwService getZsdwService() {
		return zsdwService;
	}

	public void setZsdwService(ZsdwService zsdwService) {
		this.zsdwService = zsdwService;
	}

	public String getRyid() {
		return ryid;
	}

	public void setRyid(String ryid) {
		this.ryid = ryid;
	}

	public Map<String, String> getZsdw() {
		return zsdw;
	}

	public void setZsdw(Map<String, String> zsdw) {
		this.zsdw = zsdw;
	}

	public List<XtDict> getXtdict14() {
		return xtdict14;
	}

	public void setXtdict14(List<XtDict> xtdict14) {
		this.xtdict14 = xtdict14;
	}

	public Integer getShbz() {
		return shbz;
	}

	public void setShbz(Integer shbz) {
		this.shbz = shbz;
	}

	public Integer getZfbz() {
		return zfbz;
	}

	public void setZfbz(Integer zfbz) {
		this.zfbz = zfbz;
	}
}
